/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.avbravo.couchdb;

import java.sql.ResultSet;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import org.netbeans.api.db.explorer.ConnectionManager;
import org.netbeans.api.db.explorer.DatabaseConnection;
import org.netbeans.api.db.explorer.support.DatabaseExplorerUIs;
import org.openide.util.NbBundle;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;
//import org.openide.util.ImageUtilities;
import org.openide.util.ImageUtilities;
import java.sql.Connection;
import org.netbeans.api.settings.ConvertAsProperties;
import org.openide.awt.StatusDisplayer;

/**
 * Top component which displays something.
 */
@ConvertAsProperties(dtd = "-//org.avbravo.couchdb//DemoDB//EN",
autostore = false)
public final class DemoDBTopComponent extends TopComponent {

    Sesion sesion = new Sesion();
    boolean ldatabase = false;
    boolean couchdb = false;
    private static DemoDBTopComponent instance;
    /** path to the icon used by the component and its open action */
//    static final String ICON_PATH = "SET/PATH/TO/ICON/HERE";
    private static final String PREFERRED_ID = "DemoDBTopComponent";
    static final String ICON_PATH = "org/avbravo/couchdb/couchdb-icon-16px.png";
    private DBGraphScene scene;

    public DemoDBTopComponent() {
        initComponents();
        setName(NbBundle.getMessage(DemoDBTopComponent.class, "CTL_DemoDBTopComponent"));
        setToolTipText(NbBundle.getMessage(DemoDBTopComponent.class, "HINT_DemoDBTopComponent"));
        setIcon(ImageUtilities.loadImage(ICON_PATH, true));
        DatabaseExplorerUIs.connect(dbconnComboBox, ConnectionManager.getDefault());

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToggleButton1 = new javax.swing.JToggleButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        dbconnComboBox = new javax.swing.JComboBox();
        jButtonProcesar = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldIpCouchdb = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldPuertoCouchdb = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldUserCouchdb = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jPasswordFieldCouchdb = new javax.swing.JPasswordField();
        jButtonCouchdb = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jTextFieldPrefijo = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jComboBoxFormatoFecha = new javax.swing.JComboBox();
        jButtonMigrar = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel5 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jButtonVerMensajes1 = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextAreaMensajes = new javax.swing.JTextArea();

        org.openide.awt.Mnemonics.setLocalizedText(jToggleButton1, org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jToggleButton1.text")); // NOI18N

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jPanel1.border.title"))); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jLabel1.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jButtonProcesar, org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jButtonProcesar.text")); // NOI18N
        jButtonProcesar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonProcesarActionPerformed(evt);
            }
        });

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jPanel3.border.title"))); // NOI18N

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/avbravo/couchdb/couchdb-icon-16px.png"))); // NOI18N
        org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jLabel2.text")); // NOI18N

        jTextFieldIpCouchdb.setText(org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jTextFieldIpCouchdb.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jLabel3.text")); // NOI18N

        jTextFieldPuertoCouchdb.setText(org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jTextFieldPuertoCouchdb.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel4, org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jLabel4.text")); // NOI18N

        jTextFieldUserCouchdb.setText(org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jTextFieldUserCouchdb.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel5, org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jLabel5.text")); // NOI18N

        jPasswordFieldCouchdb.setText(org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jPasswordFieldCouchdb.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jButtonCouchdb, org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jButtonCouchdb.text")); // NOI18N
        jButtonCouchdb.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCouchdbActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldPuertoCouchdb, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldIpCouchdb, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldUserCouchdb, javax.swing.GroupLayout.PREFERRED_SIZE, 209, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel5)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButtonCouchdb)
                            .addComponent(jPasswordFieldCouchdb, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE))))
                .addGap(21, 21, 21))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldIpCouchdb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextFieldPuertoCouchdb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldUserCouchdb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jPasswordFieldCouchdb, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCouchdb)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jPanel4.border.title"))); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel6, org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jLabel6.text")); // NOI18N

        jTextFieldPrefijo.setText(org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jTextFieldPrefijo.text")); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jLabel7, org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jLabel7.text")); // NOI18N

        jComboBoxFormatoFecha.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "dd/MM/aaaa", "MM/dd/aaaa", "aaaa/MM/dd", "dd/aaaa/MM", "MM/aaaa/dd", "aaaa/dd/MM" }));

        org.openide.awt.Mnemonics.setLocalizedText(jButtonMigrar, org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jButtonMigrar.text")); // NOI18N
        jButtonMigrar.setEnabled(false);
        jButtonMigrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonMigrarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(jLabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jComboBoxFormatoFecha, 0, 120, Short.MAX_VALUE)
                            .addComponent(jTextFieldPrefijo, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(75, 75, 75)
                        .addComponent(jButtonMigrar)))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(jTextFieldPrefijo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(7, 7, 7)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel7)
                    .addComponent(jComboBoxFormatoFecha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonMigrar)
                .addContainerGap(13, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(dbconnComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 312, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButtonProcesar))))
                .addContainerGap(41, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(dbconnComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonProcesar)
                .addGap(12, 12, 12)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jPanel1.TabConstraints.tabTitle"), jPanel1); // NOI18N

        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 346, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(316, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 235, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(91, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jPanel2.TabConstraints.tabTitle"), jPanel2); // NOI18N

        jPanel5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanel5MouseClicked(evt);
            }
        });

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jPanel6.border.title"))); // NOI18N

        org.openide.awt.Mnemonics.setLocalizedText(jButtonVerMensajes1, org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jButtonVerMensajes1.text")); // NOI18N
        jButtonVerMensajes1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonVerMensajes1ActionPerformed(evt);
            }
        });

        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        jScrollPane2.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

        jTextAreaMensajes.setColumns(20);
        jTextAreaMensajes.setRows(5);
        jScrollPane2.setViewportView(jTextAreaMensajes);

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addGap(68, 68, 68)
                        .addComponent(jButtonVerMensajes1))
                    .addGroup(jPanel6Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 331, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(23, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addComponent(jButtonVerMensajes1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(27, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(284, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(47, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(org.openide.util.NbBundle.getMessage(DemoDBTopComponent.class, "DemoDBTopComponent.jPanel5.TabConstraints.tabTitle"), jPanel5); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 674, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonProcesarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonProcesarActionPerformed
        // TODO add your handling code here:
        try {
            DatabaseConnection dbconn = null;
            Object selected = dbconnComboBox.getSelectedItem();
            if (selected instanceof DatabaseConnection) {
                dbconn = (DatabaseConnection) selected;
            }

            sesion.conn = dbconn.getJDBCConnection(false);
            if (sesion.conn == null) {
                ConnectionManager.getDefault().showConnectionDialog(dbconn);
            }
            if (sesion.conn == null) {
                JOptionPane.showMessageDialog(this, "Usuario no se ha conectado , realice la conexión");
                return;
            }

            //limpio la lista de tablas
            sesion.ListaTablas.clear();
            scene = new DBGraphScene(sesion.conn);

            jScrollPane1.setViewportView(scene.createView());



            JOptionPane.showMessageDialog(this, "Conectado");
            jTextFieldPrefijo.setText(sesion.conn.getCatalog() + "_");
            ldatabase = true;
            if (couchdb == true) {
                jButtonMigrar.setEnabled(true);
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getLocalizedMessage().toString());
        }
    }//GEN-LAST:event_jButtonProcesarActionPerformed

    private void jButtonCouchdbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCouchdbActionPerformed
        // TODO add your handling code here:
        try {
            String ip = jTextFieldIpCouchdb.getText();
            if (ip == null || ip.equals("")) {
                JOptionPane.showMessageDialog(this, "Ingrese el ip", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                jTextFieldIpCouchdb.requestFocus();
                return;
            }
            String spuerto = jTextFieldPuertoCouchdb.getText();
            if (spuerto == null || spuerto.equals("")) {
                JOptionPane.showMessageDialog(this, "Ingrese el puerto", "Mensaje", JOptionPane.INFORMATION_MESSAGE);
                jTextFieldPuertoCouchdb.requestFocus();
                return;
            }
            int puerto = Integer.parseInt(spuerto);

            String user = jTextFieldUserCouchdb.getText();
            if (user == null) {
                user = "";

            }
            String password = new String(this.jPasswordFieldCouchdb.getPassword());
            if (password == null) {
                password = "";

            }
            sesion.setIpCouchdb(ip);
            sesion.setPuertoCouchdb(puerto);
            sesion.setUserCouchdb(user);
            sesion.setPasswordCouchdb(password);
            couchdb = sesion.ConectarCouchDB();
            if (couchdb == false) {
                JOptionPane.showMessageDialog(this, "No se pudo establecer la conexión verifique los datos");

                return;
            }

            StatusDisplayer.getDefault().setStatusText("Conexión exitosa a couchdb");


            if (ldatabase == true) {
                jButtonMigrar.setEnabled(true);
            }
            JOptionPane.showMessageDialog(this, "Conexión exitosa a Couchdb");
        } catch (Exception ex) {

            JOptionPane.showMessageDialog(this, "Error\nMensaje: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);

        }
    }//GEN-LAST:event_jButtonCouchdbActionPerformed

    private void jButtonMigrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMigrarActionPerformed
        // TODO add your handling code here:
        sesion.ListaMensajes.clear();
        jTextAreaMensajes.setText("");
        String prefijo = jTextFieldPrefijo.getText();
        if (prefijo == null) {
            prefijo = "";
        }
        String formatoFecha = String.valueOf(jComboBoxFormatoFecha.getSelectedItem());
        sesion.setFormatoFecha(formatoFecha);
        sesion.setPrefijo(prefijo);
        StatusDisplayer.getDefault().setStatusText("Iniciando proceso de migración");
        Thread t = new Thread(new NBRunnable());
        t.start();
    }//GEN-LAST:event_jButtonMigrarActionPerformed

    private void jButtonVerMensajes1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonVerMensajes1ActionPerformed
        // TODO add your handling code here:
              // TODO add your handling code here:
   for (int i = 0; i < sesion.getListaMensajes().size(); i++) {

                jTextAreaMensajes.append(sesion.getListaMensajes().get(i) + "\n");
            }
    }//GEN-LAST:event_jButtonVerMensajes1ActionPerformed

    private void jPanel5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanel5MouseClicked
        // TODO add your handling code here:
    }//GEN-LAST:event_jPanel5MouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox dbconnComboBox;
    private javax.swing.JButton jButtonCouchdb;
    private javax.swing.JButton jButtonMigrar;
    private javax.swing.JButton jButtonProcesar;
    private javax.swing.JButton jButtonVerMensajes1;
    private javax.swing.JComboBox jComboBoxFormatoFecha;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPasswordField jPasswordFieldCouchdb;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTextArea jTextAreaMensajes;
    private javax.swing.JTextField jTextFieldIpCouchdb;
    private javax.swing.JTextField jTextFieldPrefijo;
    private javax.swing.JTextField jTextFieldPuertoCouchdb;
    private javax.swing.JTextField jTextFieldUserCouchdb;
    private javax.swing.JToggleButton jToggleButton1;
    // End of variables declaration//GEN-END:variables

    /**
     * Gets default instance. Do not use directly: reserved for *.settings files only,
     * i.e. deserialization routines; otherwise you could get a non-deserialized instance.
     * To obtain the singleton instance, use {@link #findInstance}.
     */
    public static synchronized DemoDBTopComponent getDefault() {
        if (instance == null) {
            instance = new DemoDBTopComponent();
        }
        return instance;
    }

    /**
     * Obtain the DemoDBTopComponent instance. Never call {@link #getDefault} directly!
     */
    public static synchronized DemoDBTopComponent findInstance() {
        TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
        if (win == null) {
            Logger.getLogger(DemoDBTopComponent.class.getName()).warning(
                    "Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system.");
            return getDefault();
        }
        if (win instanceof DemoDBTopComponent) {
            return (DemoDBTopComponent) win;
        }
        Logger.getLogger(DemoDBTopComponent.class.getName()).warning(
                "There seem to be multiple components with the '" + PREFERRED_ID
                + "' ID. That is a potential source of errors and unexpected behavior.");
        return getDefault();
    }

    @Override
    public int getPersistenceType() {
        return TopComponent.PERSISTENCE_NEVER;
    }

    @Override
    public void componentOpened() {
        // TODO add custom code on component opening
    }

    @Override
    public void componentClosed() {
        // TODO add custom code on component closing
    }

    void writeProperties(java.util.Properties p) {
        // better to version settings since initial version as advocated at
        // http://wiki.apidesign.org/wiki/PropertyFiles
        p.setProperty("version", "1.0");
        // TODO store your settings
    }

    Object readProperties(java.util.Properties p) {
        if (instance == null) {
            instance = this;
        }
        instance.readPropertiesImpl(p);
        return instance;
    }

    private void readPropertiesImpl(java.util.Properties p) {
        String version = p.getProperty("version");
        // TODO read your settings according to their version
    }

    @Override
    protected String preferredID() {
        return PREFERRED_ID;
    }
}
